package com.yanqu.road.server.manager.systemgroup.newmonopolymkt;

import com.yanqu.road.entity.systemgroup.newmonopolymarket.resgrab.NewMonopolyMarketResGrabMap;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.resgrab.NewMonopolyMarketResGrabPointInfo;
import org.apache.mina.util.ConcurrentHashSet;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class NewMonopolyMarketResGrab {

    /**
     * 资源分组id
     */
    int resGroupId;

    /**
     * 类型
     */
    public int type;

    /**
     * 地图信息
     */
    public NewMonopolyMarketResGrabMap map;

    /**
     * 位置信息 k:index
     */
    public Map<Integer, NewMonopolyMarketResGrabPointInfo> pointsMap = new ConcurrentHashMap<>();

    /**
     *  需要update 和add 的seatInfo 改完删除
     */
    public Set<NewMonopolyMarketResGrabPointInfo> updateAndAddPointInfoSet = new HashSet<>();

    /**
     * 玩家占领的据点集合
     */
    public Map<Long, Set<NewMonopolyMarketResGrabPointInfo>> userPointMap = new ConcurrentHashMap<>();

    /**
     * 正在采集的据点 定时器要用
     */
    public List<NewMonopolyMarketResGrabPointInfo> collectingPointInfoList = new ArrayList<>();
    /**
     * 当前采集点最近的结算时间(最大是每天的22点，如果采集快点，就会早于22点)
     * 每个资源点的采集有效时间小于或等于12个小时  10至22
     */
    public volatile int minResGrabEndTime = 0;

    /**
     *  需要检查公告的资源点
     */
    public Set<NewMonopolyMarketResGrabPointInfo> checkNoticeDataPointInfoSet = new HashSet<>();

    /**
     * 玩家 当前正在查看的据点
     */
    public Map<Long, Integer> userInPointMap = new ConcurrentHashMap<>();

    public NewMonopolyMarketResGrab(int resGroupId, int type) {
        this.resGroupId = resGroupId;
        this.type = type;
    }

    public Set<NewMonopolyMarketResGrabPointInfo> getUserPointSet(long userId, boolean newIfNull){
        Set<NewMonopolyMarketResGrabPointInfo> set = userPointMap.get(userId);
        if(set == null && newIfNull){
            synchronized (userPointMap) {
                set = userPointMap.computeIfAbsent(userId, k -> new ConcurrentHashSet<>());
            }
        }
        return set;
    }

    public int getResGroupId() {
        return resGroupId;
    }
}
